var express = require('express')
// const userRouter = require('./z_static/router/userRouter')

// 引入第三方express——jwt包
var {expressjwt}= require('express-jwt')

var app = express()


app.use(express.static('z_static'))

// 第三步骤：设置接口，处理post请求的中间件
// 想要接收post类型的请求参数，必须提前设置能解析post请求参数的中间件，下面两个就是
app.use(express.json())
app.use(express.urlencoded({ extended: false }))



// 定义返回给客户端的数据
// var arr = [
//     { email: '12333443@qq.com', name: '张三', phone: '13345678833', pass: '1234', ingroup: '测试组', admin: true, status: true },
//     { email: '12333443@qq.com', name: '李四', phone: '13345678844', pass: '1234', ingroup: '开发组', admin: true, status: true },
//     { email: '12333443@qq.com', name: '王五', phone: '13345678855', pass: '1234', ingroup: '实验组', admin: true, status: true },
//     { email: '12333443@qq.com', name: '小明', phone: '13345678866', pass: '1234', ingroup: '测试组', admin: true, status: false },
//     { email: '12333443@qq.com', name: '小张', phone: '13345678877', pass: '1234', ingroup: '编辑组', admin: true, status: true },
//     { email: '12333443@qq.com', name: '小胡', phone: '13345678888', pass: '1234', ingroup: '开发组', admin: true, status: true },
//     { email: '12333443@qq.com', name: '小马', phone: '13345678899', pass: '1234', ingroup: '测试组', admin: true, status: false }

// ]
// 导入拆分出去的子路由
var userRouter  = require('./z_static/router/userRouter')
var goodRouter  = require('./z_static/router/goodRouter')
// 注册子路由
app.use('/user',userRouter)
app.use('/good',goodRouter)

// 设置token验证的中间件
app.use(expressjwt({
    secret: '1234',//密钥
    algorithms: ['HS256'],//解密密钥算法
}).unless({path:['/user/login','/user/register']}));//设置白名单，免除token验证 


// 设置接口



// 设置监听
app.listen(8080,()=>{
    console.log('服务端运行在: http://localhost:8080');
})